@extends('common.base-master')

@section('html-head')
    <link rel="stylesheet" type="text/css" href="{{url('css/bootstrap.min.css')}}">
    <link href="{{url('css/cre-project.css')}}" type="text/css" rel="stylesheet">
    <script src="{{url('js/cre-project.js')}}"></script>
@endsection

@section('html-body')
    <main>
        <div class="wrapp">
            <div class="contain">
                <section class="cre-pro">
                    <h1>快速创建项目</h1>
                    <div class="head-line">
                        <p class="c-1 c-t"><em>1</em><i>项目信息</i></p>
                        <p class="c-1 c-t-s"><em>2</em><i>需求</i></p>
                        <p class="desc">
                            投资人首先会看到项目信息，这些信息决定其是否对你的项目感兴趣，请认真填写~
                        </p>
                    </div>

                    <div class="table-box">
                        <ul>
                            <li><em class="pro-name"><em class="c-m">*</em><em class="c-name">项目名称</em></em><em class="c-i"><input type="text" id="projectName" /></em></li>
                            <li><em class="error c-e-1">123</em></li>
                            <li class="c-area"><em class="pro-name"><em class="c-m">*</em><em class="c-name">一句话介绍</em></em><em class="c-i"><textarea id="projectintro"></textarea></em><p><em class="re-num">0</em>/30</p></li>
                            <li><em class="error c-e-2">123</em></li>
                            <li><em class="pro-name"><em class="c-m">*</em><em class="c-name">产品LOGO</em></em><a class="logo" href="javascript:void(0);" id="inputImage"><img id="project_logo_url" src="{{route('Api.Images.Show')}}" title="点击上传logo" /></a><input type="hidden" id="project_logo_id" value="{{\Illuminate\Support\Facades\Session::get('ImageId') == ''? 0:\Illuminate\Support\Facades\Session::get('ImageId')}}" /><em class="msg"></em><em class="c-u-d">请上传 256 x 256 以上像素的图片，</em><em class="c-u-d">格式为JPG、JPEG、PNG，小于5MB</em></li>
                            <li><em class="pro-name"><em class="c-m">*</em><em class="c-name">产品状态</em></em>
                                <select class="c-s" id="projectStatus">
                                    <option value="DEMO">DEMO</option>
                                    <option value="研发中">研发中</option>
                                    <option value="初上线">初上线</option>
                                    <option value="运营中">运营中</option>
                                    <option value="已盈利">已盈利</option>
                                </select>
                            </li>
                            <li><em class="pro-name"><em class="c-m">*</em><em class="c-name">所属行业</em></em>
                                <div class="c-m-list">
                                    <ul>
                                        @foreach($fields as $field)
                                            <li><input name="checkbox" id="projectFields" type="checkbox" value="{{$field->id}}" />{{$field->field}}</li>
                                        @endforeach
                                    </ul>
                                </div>
                            </li>
                            <li><em class="pro-name"><em class="c-m">*</em><em class="c-name">产品链接</em></em>
                                <div class="c-m-i c-m-f">
                                    <ul>
                                        <li><input type="text" placeholder="官方网站，以“http://”开头" class="c-url" /></li>
                                        <li><input type="text" placeholder="IOS 地址，以“http://”开头" class="i-url" /></li>
                                        <li><input type="text" placeholder="安卓地址，以“http://”开头" class="a-url"/></li>
                                    </ul>
                                </div>
                            </li>
                            <li><em class="pro-name"><em class="c-m">*</em><em class="c-name">团队信息</em></em>
                                <div class="c-m-i c-m-s">
                                    <span><input type="text" placeholder="成员姓名" class="mem-name"> - <input type="text" placeholder="职位头衔" class="job-title"> <button class="c-m-btn">添加</button></span>
                                    <div><p class="error c-m-err-m" >123</p><p class="error c-m-err-j">123</p></div>
                                </div>
                                <div class="c-m-i c-m-t">
                                    <ul>
                                        @foreach($projectTeams as $projectTeam)
                                        <li name="teamname" pro_team_id="{{$projectTeam->id}}"><em class="name">{{$projectTeam->real_name}} - {{$projectTeam->position}}</em><button class="c-m-remove">删除</button></li>
                                        @endforeach
                                    </ul>

                                </div>
                            </li>
                            <li class="c-next"><em class="c-desc">你希望通过旁观者创投平台获得什么？</em><button>下一步</button></li>
                        </ul>
                    </div>
                </section>
            </div>
        </div>
    </main>
    <script type="text/javascript">
    var setProjectTeamByUserId = "{{route('Api.Project.SetProjectTeamByUserId')}}";
    var delProjectTeamById     = "{{route('Api.Project.DelProjectTeamById')}}";
    var cre_need               = "{{route('Home.Project.showCreateProjectNeed')}}";
    var createProject          = "{{route('Api.Project.EditProject',['id'=>0])}}";
    </script>
    <script>
        var uploader = new plupload.Uploader({
            runtimes: 'html5,flash,silverlight,html4',
            browse_button: 'inputImage',
            url: '{{ url('api/upload/image')  }}',

            chunk_size: '2mb',
            filters: {
                max_file_size: '10mb',
                mime_types: [
                    {title: "Image files", extensions: "jpg,gif,png"}
                ],
                prevent_duplicates: false
            },
            multi_selection: true,
            unique_names: true,

            flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
            silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

            file_data_name: 'photo',
            headers: {
                Accept: 'application/json'
            },

            multipart_params: {
                _token: '{{ csrf_token() }}'
            },

            init: {
                PostInit: function () {
                },

                FilesAdded: function (up, files) {
                    up.start();
                },

                BeforeUpload: function (up, file) {
                    up.settings.multipart_params.file_name = file.name;
                },

                UploadProgress: function (up, file) {
                    $('.msg').html('上传中...');
                },

                Error: function (up, err) {
                    var responseObj = '', responseMessage = '';
                    try {
                        responseObj = $.parseJSON(err.response);
                        responseMessage = responseObj.message;
                    } catch ($e) {

                    }

                    noty({
                        type: 'error',
                        text: err.message + ' ' + responseMessage,
                        callback: {
                            afterClose: function () {
                                $('#inputImage').show();
                                $('#inputImageProgress').hide();
                            }
                        }
                    });
                },

                FileUploaded: function (up, file, info) {
                    var responseObj = '', responseMessage = '';
                    try {
                        responseObj = $.parseJSON(info.response);
                        responseMessage = responseObj.message;
                    } catch ($e) {

                    }

                    var $inputImage = $('.msg');
                    $inputImage.html('上传成功！');
                    $inputImage.show();

                    var imageUrl = '', imageId = 0;
                    if (responseObj && responseObj.data) {
                        var d = new Date();
                        imageUrl = "{{route('Api.Images.Show')}}?"+d.getTime();
                        imageId = responseObj.data.id;
                    }
                    $('#project_logo_url').attr('src', imageUrl);
                    if(imageId !== null){
                        $('#project_logo_id').val(imageId);
                    }else{
                        $('#project_logo_id').val('0');
                    }
                }
            }
        });
        uploader.init();
    </script>
@endsection